package com.lifesea.notify.mq.consumer;


import com.alibaba.rocketmq.client.exception.MQClientException;
import com.lifesea.commons.mq.entity.MqTopicConst;
import com.lifesea.conifg.PublicConfig;
import com.lifesea.notify.mq.handler.BookOrderNotifyAppHandler;
import com.lifesea.rocketmq.utils.manager.DefaultMessageConsumerManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * 预约挂号通知居民端事件处理
 */
@Component
public class BookNotifyAppMqConsumer {

    private static final Logger logger = LoggerFactory.getLogger(BookNotifyAppMqConsumer.class);

    private DefaultMessageConsumerManager consumerManager;
    @Autowired
    private BookOrderNotifyAppHandler bookOrderNotifyAppHandler;

    @PostConstruct
    public void init() throws MQClientException {
        consumerManager = new DefaultMessageConsumerManager();
        consumerManager.setNamesrvAddr(PublicConfig.ROCKETMQ_NAMESRVADDR);
        consumerManager.setConsumerGroup(MqTopicConst.GROUP_BOOK_ORDER_NOTIFY);
        consumerManager.register(MqTopicConst.TOPIC_BOOK, MqTopicConst.TAG_BOOK_ORDER, bookOrderNotifyAppHandler);// 通知家医
        consumerManager.init();
    }

    @PreDestroy
    public void destroy() {
        consumerManager.destroy();
    }


}
